package com.boot2.core.dao.mybatis;

import com.alibaba.fastjson.annotation.JSONField;
import com.boot2.core.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangweilin
 * @date 2018/7/4 17:08
 * @description:所有mybatis po父类
 */
@MappedSuperclass
public class MyBatisSupportEntity extends BaseEntity implements Entity {

    private static final long serialVersionUID = 1L;

    public MyBatisSupportEntity() {
    }

    public MyBatisSupportEntity(boolean isInit) {
        super(isInit);
    }

    /**
     * 对应的操作符号
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient Map<String, String> signMap = null;
    /**
     * 是否自动sql
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient Boolean isAutoSql = false;

    /**
     * id集合，用来做in处理，一般为查询
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<Serializable> ids;
    // private List<Integer> idList;

    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient String pkName;

    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient String pkColumnName;

    /**
     * 用来生成所有字段
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<? extends MyBatisType> allMybatisTypeList = null;

    /**
     * 用来生成所有字段,不同数据库区别对待pk
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<? extends MyBatisType> allMybatisTypePkList = null;
    /**
     * 用来生成有值的字段
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<? extends MyBatisType> hasValueMybatisTypeList = null;

    /**
     * 用来生成有值的字段,不同数据库区别对待pk
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<? extends MyBatisType> hasValueMybatisTypePkList = null;
    /**
     * 用来生成有值的字段
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<? extends MyBatisType> hasValidValueMybatisTypeList = null;

    /**
     * 用来生成有值的字段,不同数据库区别对待pk
     */
    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<? extends MyBatisType> hasValidValueMybatisTypePkList = null;

    @JsonIgnore // jackson不序列化
    @JSONField(serialize = false) // fast不序列化
    @Transient
    private transient List<String> toNullColumnList = null;


    public void putSignMap(String key, String value) {
        FullMatchedDbColumn fullMatchedDbColumn = this.getClass().getAnnotation(FullMatchedDbColumn.class);
        if (null == signMap) {
            signMap = new HashMap<String, String>();
        }
        signMap.put(MyBatisDaoUtil.getColumnName(key, fullMatchedDbColumn), value);
        // System.out.println("signMap: "+signMap);
    }

    @Transient
    public Map<String, String> getSignMap() {
        return signMap;
    }

    // public void setSignMap(Map<String, String> signMap)
    // {
    // this.signMap = signMap;
    // }
    public List<? extends MyBatisType> getAllMybatisTypeList() {
        return allMybatisTypeList;
    }

    @SuppressWarnings("unused")
    private void setAllMybatisTypeList(final List<? extends MyBatisType> allMybatisTypeList) {
        // System.out.println("setAllMybatisTypeList: "+allMybatisTypeList);
        this.allMybatisTypeList = allMybatisTypeList;
    }

    public List<? extends MyBatisType> getHasValueMybatisTypeList() {
        return hasValueMybatisTypeList;
    }

    @SuppressWarnings("unused")
    private void setHasValueMybatisTypeList(final List<? extends MyBatisType> hasValueMybatisTypeList) {
        this.hasValueMybatisTypeList = hasValueMybatisTypeList;
    }

    @SuppressWarnings("unused")
    public void setIds(final List<Serializable> ids) {
        this.ids = ids;
    }

    public List<? extends MyBatisType> getAllMybatisTypePkList() {
        return allMybatisTypePkList;
    }

    @SuppressWarnings("unused")
    private void setAllMybatisTypePkList(final List<? extends MyBatisType> allMybatisTypePkList) {
        this.allMybatisTypePkList = allMybatisTypePkList;
    }

    public List<? extends MyBatisType> getHasValueMybatisTypePkList() {
        return hasValueMybatisTypePkList;
    }

    @SuppressWarnings("unused")
    private void setHasValueMybatisTypePkList(final List<? extends MyBatisType> hasValueMybatisTypePkList) {
        this.hasValueMybatisTypePkList = hasValueMybatisTypePkList;
    }

    private Boolean getIsAutoSql() {
        return isAutoSql;
    }

    @SuppressWarnings("unused")
    public void setIsAutoSql(final Boolean isAutoSql) {
        this.isAutoSql = isAutoSql;
    }

    public List<String> getToNullColumnList() {
        return toNullColumnList;
    }

    @SuppressWarnings("unused")
    private void setToNullColumnList(List<String> toNullColumnList) {
        this.toNullColumnList = toNullColumnList;
    }

    public String getPkName() {
        return pkName;
    }

    private void setPkName(String pkName) {
        this.pkName = pkName;
    }

    public String getPkColumnName() {
        return pkColumnName;
    }

    private void setPkColumnName(String pkColumnName) {
        this.pkColumnName = pkColumnName;
    }

    public List<? extends MyBatisType> getHasValidValueMybatisTypeList() {
        return hasValidValueMybatisTypeList;
    }

    public void setHasValidValueMybatisTypeList(List<? extends MyBatisType> hasValidValueMybatisTypeList) {
        this.hasValidValueMybatisTypeList = hasValidValueMybatisTypeList;
    }

    public List<? extends MyBatisType> getHasValidValueMybatisTypePkList() {
        return hasValidValueMybatisTypePkList;
    }

    public void setHasValidValueMybatisTypePkList(List<? extends MyBatisType> hasValidValueMybatisTypePkList) {
        this.hasValidValueMybatisTypePkList = hasValidValueMybatisTypePkList;
    }
}
